<%--
  Created by IntelliJ IDEA.
  User: caidao
  Date: 2023/4/17
  Time: 08:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
    <head>
        <title>Title</title>
        <jsp:include page="/WEB-INF/include/bootstrapHeader.jsp"/>
        <link rel="stylesheet" href="<c:url value="/css/main.css"/>"/>
    </head>
    <body class="d-flex flex-column h-100">
        <jsp:include page="/WEB-INF/include/pageHeader.jsp"/>

        <main class="flex-shrink-0">
            <div class="container">
                <div class="col-6">
                    <h1 class="mt-5">消费记录</h1>
                </div>
                <div class="col-6">
                    <a href="<c:url value="/paid/new"/>" class="btn btn-primary">新增</a>
                </div>
                <c:if test="${sessionScope.msg != '' && sessionScope.msg != null}">
                    <div class="alert alert-primary" role="alert" style="margin-top: 15px;" id="msgBox">
                        <c:out value="${sessionScope.msg}" />
                    </div>
                    <c:set var="msg" scope="session" value=""/>
                    <script>
                        setTimeout(function () {
                            document.querySelector('#msgBox').style.display = 'none';
                        }, 10000);
                    </script>
                </c:if>
                <table class="table">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>支出类型</th>
                        <th>商品名称</th>
                        <th>消费时间</th>
                        <th>支出金额</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        <c:forEach var="paid" varStatus="status" items="${list}">
                            <tr>
                                <td><c:out value="${status.index + 1}"/></td>
                                <td><c:out value="${paid.paidtype}"/></td>
                                <td><c:out value="${paid.paidname}"/></td>
                                <td>
        <%--                            <c:out value="${paid.paiddate}"/>--%>
                                    <fmt:formatDate value="${paid.paiddate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                </td>
                                <td><c:out value="${paid.amountpaid}"/></td>
                                <td>
                                    <a href="<c:url value="/paid/edit?id=${paid.id}"/>"><i class="bi bi-pencil"></i></a>
                                    <a href="<c:url value="/paid/delete?id=${paid.id}"/>" onclick="return myConfirm();"><i class="bi bi-trash"></i></a>
                                </td>
                            </tr>
                        </c:forEach>
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="4">合计</td>
                        <td colspan="2"><c:out value="${total}"/></td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </main>
        <jsp:include page="/WEB-INF/include/pageFooter.jsp"/>
        <script>
            function myConfirm() {
                //confirm javascript的函数，弹个确认框
                let result = confirm('将要删除数据，是否继续？');
                console.log(result);
                return result;
            }
        </script>
    </body>

</html>
